import Redis from 'ioredis';
const redis = new Redis();


// 订阅频道的函数
async function subscribeChannel(channelName:any) {
    try {
        console.log(`Subscribing to channel ${channelName}...`);

        // 创建 Redis 客户端并订阅指定频道
        redis.subscribe(channelName);

        // 监听消息
        redis.on('message', (channel, message) => {
            console.log(`Received message on channel ${channel}: ${message}`);
        });

    } catch (error) {
        console.error('Error subscribing to channel:', error);
    }
}

// 例子
const channelName = 'myChannel';

// 创建多个订阅者
subscribeChannel(channelName);